from django.db import models


# Create your models here.


class Category(models.Model):
    """
    一个类对应一个数据表，每一个字段都是一列
    """
    title = models.CharField(verbose_name='分类名', max_length=30, unique=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "分类"
        verbose_name_plural = "分类"


class Book(models.Model):
    title = models.CharField(verbose_name='书名', max_length=30, unique=True)
    category = models.ForeignKey(verbose_name='所属分类', to='Category', on_delete=models.CASCADE)
    pub_date = models.DateField(verbose_name='出版时间', auto_now_add=True)
    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "书籍"
        verbose_name_plural = "书籍"


class Ads(models.Model):
    title = models.CharField(verbose_name="轮播图", max_length=20)
    url = models.URLField(verbose_name="链接地址")
    img = models.ImageField(verbose_name="图片", upload_to="Abs")

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "轮播图"
        verbose_name_plural = "轮播图"
